package whf.survey.entity;

import java.util.Collections;
import java.util.List;
import java.util.Set;

import whf.framework.util.Utils;

/**
 * @author wanghaifeng
 * @create Sep 12, 2006 10:16:38 PM
 * 
 */
public class SurveyTopic extends whf.framework.entity.AbstractEntity {

	private static final long serialVersionUID = 0;

	private String choiceType;

	private whf.survey.entity.Survey survey;
	
	private int sortOrder;

	private Set<SurveyTopicChoice> choices = Utils.newHashSet();
	// ---------- methods ----------


	public void setSurvey(whf.survey.entity.Survey survey) {
		this.survey = survey;
	}

	public whf.survey.entity.Survey getSurvey() {
		return this.survey;
	}

	/**
	 * @return Returns the choices.
	 */
	public final Set<SurveyTopicChoice> getChoices() {
		return choices;
	}

	/**
	 * @param choices The choices to set.
	 */
	public final void setChoices(Set<SurveyTopicChoice> choices) {
		this.choices = choices;
	}

	public final void addChoice(SurveyTopicChoice c){
		this.choices.add(c);
	}
	
	public final void remove(SurveyTopicChoice c){
		this.choices.remove(c);
	}

	/**
	 * @return Returns the sortOrder.
	 */
	public final int getSortOrder() {
		return sortOrder;
	}

	/**
	 * @param sortOrder The sortOrder to set.
	 */
	public final void setSortOrder(int sortOrder) {
		this.sortOrder = sortOrder;
	}
	
	public List<SurveyTopicChoice> getSortChoices(){
		List<SurveyTopicChoice> list = Utils.newArrayList();
		list.addAll(this.choices);
		Collections.sort(list);
		return list;
	}

	/* (non-Javadoc)
	 * @see whf.framework.entity.AbstractEntity#compareTo(java.lang.Object)
	 */
	@Override
	public int compareTo(Object obj) {
		return this.sortOrder - ((SurveyTopic)obj).sortOrder;
	}

	/**
	 * @return the choiceType
	 */
	public String getChoiceType() {
		return choiceType;
	}

	/**
	 * @param choiceType the choiceType to set
	 */
	public void setChoiceType(String choiceType) {
		this.choiceType = choiceType;
	}
	
	
}